#ifndef _CustomMaterial_H_
#define _CustomMaterial_H_

#pragma once
#include "Material.h"
class CustomMaterial : public Material {
	typedef function<Color(const Scene *, const Ray &, const IntersectResult &)> ShadeFunc;
private:
	ShadeFunc shadeFunction = nullptr;
	ShadeFunc transparentColorFunc = nullptr;
	bool luminous = false;
	bool transparent = false;

public:
	CustomMaterial(ShadeFunc shadeFunction, ShadeFunc tcf = nullptr, Float strength = 1) :
		Material(strength), shadeFunction(shadeFunction), transparentColorFunc(tcf) {}
	~CustomMaterial() {}

	Material * setShadeFunc(ShadeFunc shadeFunction) {
		this->shadeFunction = shadeFunction;
		return this;
	}

	Material * setLuminous(bool luminous) {
		this->luminous = luminous;
		return this;
	}

	Material * setTransparent(bool transparent) {
		this->transparent = transparent;
		return this;
	}

	Material * setTransparentColorFunc(ShadeFunc tcf) {
		transparentColorFunc = tcf;
		return this;
	}

	Color shade(const Scene *scene, const Ray &ray, const IntersectResult &intersect, const TraceState & traceState) const {
		return strength * shadeFunction(scene, ray, intersect);
	}
	bool isLuminous() const {
		return luminous;
	}
	bool isTransparent() const {
		return transparent;
	}
	Color getTransparentColor(const Scene * scene, const Ray & ray, const IntersectResult &intersect) const {
		return transparentColorFunc ? transparentColorFunc(scene, ray, intersect) : Colors::Black;
	}
};

#endif // _CustomMaterial_H_